import {Component} from "@angular/core";
import {MessageService} from "../../service/message/message.service";
import {UserData} from "../../common/user.data";
import {ToastController} from "ionic-angular";

@Component({
  selector: 'page-message',
  templateUrl: 'message.html',
  providers: [MessageService]
})

export class MessagePage {

  private message: any = {
    data: [],
    page: 0,
    size: 20,
    loadOver: false
  };

  constructor(private messageService: MessageService, private user: UserData, private toast: ToastController) {
    this.queryMessage();
  }

  private queryMessage() {
    this.messageService.findByToken({
      token: this.user.token,
      size: this.message.size,
      page: this.message.page
    }).subscribe(res => {
      this.message.data = res.data;
    }, () => {
      this.toast.create({
        message: '连接异常,请稍后重试!',
        duration: 2000,
        position: 'top'
      }).present();
    });
  }
}
